package gs.wicket.app.session;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import java.util.Properties;

import org.apache.wicket.Request;

import gs.wicket.app.account.Korisnik;

public class GSSession extends WiaSession{

	private Cart cart = new Cart();
	private Korisnik logovanKorisnik;
	private Properties langProperties;
	private static final long serialVersionUID = 6299461726226682020L;
	
	ArrayList<Korisnik> korisnici = new ArrayList<Korisnik>() {
		private static final long serialVersionUID = 1L;
	};
	
	public GSSession(Request request) {
	    super(request);
	    
	    Locale l = new Locale("ba", "BIH");
		setLocale(l);
		langProperties = new Properties();
		
		
		try {
			langProperties.load(new FileInputStream("WEB-INF/languageProperties/language_"+getLocale().getLanguage()+".properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	  }
	
	public void setLanguage(String langCode) {
		Locale l = null;
		if ("en".equalsIgnoreCase(langCode)) {
			l = new Locale("en", "USA");
		} else {
			l = new Locale("ba", "BIH");
		}
		setLocale(l);
		try {
			langProperties.load(new FileInputStream("WEB-INF/languageProperties/language_"+getLocale().getLanguage()+".properties"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public String getLanguage() {		
		return getLocale().getLanguage();
	}
	
	public String getLangProperty(String key){
		return langProperties.getProperty(key) ==  null ? "Missing property: "+key:langProperties.getProperty(key);
	}

	  public Cart getCart() {
	    return cart;
	  }
	  
	  public ArrayList<Korisnik> getKorisnici() {
			return korisnici;
		}
	  
	  public Korisnik getLogovanKorisnik() {
			return logovanKorisnik;
		}

	  public void setLogovanKorisnik(Korisnik logovanKorisnik) {
			this.logovanKorisnik = logovanKorisnik;
		}
}
